package ex2.grammars.factories;

import ex2.Token;
import ic.ast.decl.ClassType;
import ic.ast.decl.PrimitiveType;
import ic.ast.decl.Type;

/**
 * Created with IntelliJ IDEA.
 * User: Roi
 * Date: 11/23/13
 */
public class TypeFactory {

    /**
     * Creates type according to token
     * @param token token
     * @return create type
     */
    public static Type create(Token token) {
        switch (token.tag) {
            case "int":
                return new PrimitiveType(token.getLine(), PrimitiveType.DataType.INT);
            case "string":
                return new PrimitiveType(token.getLine(), PrimitiveType.DataType.STRING);
            case "boolean":
                return new PrimitiveType(token.getLine(), PrimitiveType.DataType.BOOLEAN);
            default:
                return new ClassType(token.getLine(), token.getValue());
        }
    }
}
